package com.springclouddemo.common.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {

    /**
     * 当天00:00:00
     * @return
     */
    public static Date getToday(){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        Date zero = calendar.getTime();
        return zero;
    }
    /**
     * 日期格式化
     * @param date 日期
     * @param format 格式(yyyyMMddHHmmss)
     * @return
     */
    public synchronized static String toString(Date date,String format) {
        DateFormat dateFormat = new SimpleDateFormat(format);
        return dateFormat.format(date);

    }
}
